﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.OracleClient;
using System.Data;
using System.Web.Configuration;
using System.Collections;
using System.Reflection;
 public class ConnForOracle
   {
    protected OracleConnection Connection;
    private string connectionString;
    public ConnForOracle()
    {
   
    }
 
    #region 带参数的构造函数
    /// <summary>
    /// 带参数的构造函数
    /// </summary>
    /// <param name="ConnString">数据库联接字符串</param>
    public ConnForOracle(string ConnString)
    {
        Connection = new OracleConnection(ConnString);
    }
    #endregion
 
    #region 打开数据库
    /// <summary>
    /// 打开数据库
    /// </summary>
    public void OpenConn()
    {
     if(this.Connection.State!=ConnectionState.Open)
      this.Connection.Open();
    }
    #endregion
    #region 关闭数据库联接
    /// <summary>
    /// 关闭数据库联接
    /// </summary>
    public void CloseConn()
    {
     if(Connection.State==ConnectionState.Open)
      Connection.Close();
    }
    #endregion

    public DataTable Select(string sql, OracleParameter cmdParms)
    {
    
        OracleCommand cmd = new OracleCommand(sql, Connection);
        if (cmdParms != null)
        {
            cmd.Parameters.Add(cmdParms);
        }
        OracleDataAdapter oda = new OracleDataAdapter(cmd);
        DataTable dt = new DataTable();
        oda.Fill(dt);
        Connection.Close();
        cmd.Dispose();
        return dt;
    }

    public int Update(string sql, OracleParameter[] cmdParms)
    {

        OracleCommand cmd = new OracleCommand(sql, Connection);
        if (cmdParms != null)
        {
            cmd.Parameters.Add(cmdParms);
        }
        int result = cmd.ExecuteNonQuery();
        Connection.Close();
        cmd.Dispose();
        return result;
    }
   }